<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('器材型号列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 器材类型
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="validDeviceType()" title="管理器材类型"><i class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新器材类型"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>器材类型：</label>
                                <div class="input-group">
                                    <input name="typeName" onclick="gotoSelectValidDeviceTypeTree()" autocomplete="off"  id="typeName" type="text" placeholder="请选择器材类型" >
                                    <!--                                    <span class="input-group-addon"><i class="fa fa-search"></i></span>-->
                                    <input type="text" name="typeId"  id="typeId"  autocomplete="off" hidden/>
                                </div>
                            </li>
                            <li>
                                <label>器材型号：</label>
                                <input type="text" name="modeName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="valid" th:with="type=${@dict.getType('sys_valid')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:mode:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:mode:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:mode:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:mode:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:mode:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:mode:remove')}]];
        var prefix = ctx + "system/mode";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryDeviceModeList();
            getValidDeviceTypeTree();
        });
        var validDatas = [[${@dict.getType('sys_valid')}]];
        var unitDatas = [[${@dict.getType('sys_unit')}]];
        function queryDeviceModeList(){
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "器材型号",
                columns: [{
                    radio: true
                },
                    {
                        field: 'id',
                        title: '主键ID',
                        visible: false
                    },
                    {
                        field: 'modeName',
                        title: '器材'
                    },
                    {
                        field: 'unit',
                        title: '单位',
                        formatter:function (value,row,index){
                            return $.table.selectDictLabel(unitDatas, value);
                        }
                    },
                    {
                        field: 'sequence',
                        title: '顺序'
                    },
                    {
                        field: 'valid',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(validDatas, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }, {
                        field: 'createTime',
                        title: '创建时间'
                    },{
                        field: 'updateTime',
                        title: '最近更新时间'
                    }]
            };
            $.table.init(options);
        }

        function getValidDeviceTypeTree() {
            var url = ctx + "system/type/getValidDeviceTypeTree";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#typeId").val(treeNode.id);
                $("#typeName").val(treeNode.name);
                $.table.search();
            }
        }

        /* 设备管理-设备类型 */
        function validDeviceType() {
            var url = ctx + "system/type";
            $.modal.openTab("器材类型管理", url);
        }
        $('#btnRefresh').click(function() {
            getValidDeviceTypeTree();
        });
        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        /* 器材管理-选择器材类型名称 */
        function gotoSelectValidDeviceTypeTree() {
            var url = ctx + "system/type/gotoDeptTree";
            var options = {
                title: '选择器材类型',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#typeId").val(body.find('#deviceTypeId').val());
            $("#typeName").val(body.find('#deviceTypeName').val());
            layer.close(index);
        }
    </script>
</body>
</html>